package com.kkyy.msystem.controller;

import com.kkyy.msystem.feign.FeignService;
import com.kkyy.msystem.service.UsersService;
import com.kkyy.msystem.vo.MvVo;
import com.kkyy.msystem.vo.PlayListVo;
import com.kkyy.msystem.vo.SongVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping("/msystem")
public class AddController {
    @Autowired
    FeignService feignService;

    @Autowired
    UsersService usersService;

    @RequestMapping("/add")
    public String add() {
        return "addPage";
    }

    // 添加轮播图
    @RequestMapping("/addBannerUrl")
    @ResponseBody
    public String addBannerUrl(String url) {
        // http://包含在0的索引位置
        if (url.indexOf("http://") == 0 || url.indexOf("https://") == 0) {
            // 成功可插入
            feignService.addBannerUrl(url);
            return "添加成功！";
        } else {
            return "请输入合法的地址！";
        }
    }

    // 添加mv
    @RequestMapping("/addMv")
    @ResponseBody
    public String addMv(MvVo mv) {
        if (mv.getPicurl().indexOf("http://") == 0 || mv.getPicurl().indexOf("https://") == 0) {
            feignService.addMvInfo(mv.getPicurl(), mv.getCount(), mv.getMvreco(), mv.getMvart(), mv.getMvname(), mv.getLocation());
            return "添加成功！";
        } else {
            return "请输入合法的地址！";
        }
    }

    // 添加最新音乐
    @RequestMapping("/addSong")
    @ResponseBody
    public String addSong(SongVo song) {
        if (song.getPicurl().indexOf("http://") == 0 || song.getPicurl().indexOf("https://") == 0) {
            feignService.addSongInfo(song.getSongname(), song.getSongart(), song.getPicurl(), song.getLocation());
            return "添加成功！";
        } else {
            return "请输入合法的地址！";
        }
    }

    // 添加推荐歌单
    @RequestMapping("/addPlaylist")
    @ResponseBody
    public String addPlaylist(PlayListVo playlist) {
        if (playlist.getPicurl().indexOf("http://") == 0 || playlist.getPicurl().indexOf("https://") == 0) {
            feignService.addPlaylist(playlist.getCopywriter(), playlist.getPicurl(), playlist.getPlaylistname(), playlist.getLocation());
            return "添加成功！";
        } else {
            return "请输入合法的地址！";
        }
    }
}